class P636_39643 {

	public static void main(String[] args) {
		while (true) {
			String i = readLn();
			
			if ("0".equals(i)) break;
			
			for (int k = 1; k  < 100; k++) {
				long j = parse(i, k);
				
				if (j == -1) continue;
				
				long sqrt = (long) Math.sqrt(j);
				
				if (sqrt * sqrt == j) {
					System.out.println(k);
					break;
				}
				
				
			}
			
		}
	}
	
	private static long parse(String i, int k) {
//		System.out.println("parse " + i + ", base " + k);
		long sum = 0;
		
		for (int j = 0; j < i.length(); j++) {
			if (i.charAt(j) >= ('0' + k)) return -1;
//			System.out.println("> " + (i.charAt(j) - '0'));
//			System.out.println(i.length() - j + 1);
			
			sum += ((int)(i.charAt(j) - '0')) *  Math.pow(k, i.length() - j + 1);
		}
		
//		System.out.println(sum);
		return sum;
	}

	static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuffer buffer = new StringBuffer();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char)car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
            System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) { return (null);}
        if ((car < 0) && (buffer.length() == 0)) return (null);
        return (buffer.toString()).trim();
    }
	
}
